﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace Ssb
{
    /// <summary>
    /// The animation class holds a series of textures that are drawn onto a common position.
    /// The FighterAnimation class also holds hitboxes and GFX/SFX information.
    /// </summary>
    public class Animation 
        : DrawableGameComponent
    {
        public int CurrentFrame { get; protected set; }
        public int Frames { get; protected set; }

        public List<Texture2D> Anim { get; protected set; }

        public SpriteBatch sb;

        private Vector2 coords;
        public Vector2 Coords
        {
            get
            {
                return coords;
            }
            set
            {
                coords = value;
            }
        }

        public float X
        {
            get
            {
                return Coords.X;
            }
            set
            {
                coords.X = value;
            }
        }

        public float Y
        {
            get
            {
                return Coords.Y;
            }
            set
            {
                coords.Y = value;
            }
        }

        public Animation(Vector2 location, List<Texture2D> textures, Game game)
            : base(game)
        {
            CurrentFrame = 0;
            Frames = textures.Count;

            Anim = textures;
            Coords = location;
        }

        public override void Initialize()
        {
            sb = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));

            base.Initialize();
        }

        public override void Draw(GameTime gt)
        {
            sb.Draw(Anim[CurrentFrame], Coords, Color.White);
        }

        public override void Update(GameTime gt)
        {
            CurrentFrame++;
            if (CurrentFrame >= Frames)
            {
                CurrentFrame = 0;
            }
        }
    }
}
